function page(flag) {

	if (flag == "first") {
		$currentpage = 1;
	} else if (flag == "last") {
		$currentpage = $totalpage;
	} else if (flag == "prev") {
		if ($currentpage - 1 <= 0) {
			return;
		}
		$currentpage--;
	} else if (flag == "next") {
		if ($currentpage + 1 > $totalpage) {
			return;
		}
		$currentpage++
	} else if (!isNaN(flag)) {
		if (flag > $totalpage || flag < 1) {
			alert("超出范围");
			return;
		}
		$currentpage = flag * 1;
	}
	$("#w-page").val($currentpage);
	// 由于调用了API的page对象，所以这里$offset 要等于$currentpage
	$offset = $currentpage;
	service.getDataSourcesByPage($offset, $pagesize, "", "", "", dsCB);
}

var dsCB = function(data) {
	var json = eval("(" + data + ")");
	var list = json.list;
	$total = json.page.totalRecord;
	$totalpage = Math.ceil($total / $pagesize);
	$("#c-page").html($currentpage);
	$("#t-page").html($totalpage == 0 ? 1 : $totalpage);
	var str = '';
	for (i = 0; i < list.length; i++) {
		var ds = list[i];
		var nextRun = ds.nextRun;
		nextRun == 0 ? nextRun = new Date(ds.backupTime).toLocaleString()
				: nextRun = new Date(ds.nextRun).toLocaleString()
		var version = ds.currentVersionMajor + "." + ds.currentVersionMinor;
		str += "<tr><td>" + ds.name + "</td>";
		str += "<td>" + ds.root + "</td>";
		if(ds.status == "4"){
			str += "<td>数据源被禁用</td>";
		}else{
			if (ds.dsType != "2") {
				str += "<td>下次备份时间：" + nextRun + "</td>";
			} else {
				str += "<td>保险箱数据，等待手动备份</td>";
			}
		}
		if (ds.count > 0) {
//			str += "<td><a href='file_list.html?dsId=" + ds.id + "&version="
//					+ version + "'>浏览文件</a></td>";
			var url="file_list.html?dsId=" + ds.id +"&root="+ encodeURI(encodeURI(ds.root))+ "&version="+ version
			str += "<td><a href='"+url+"'>浏览文件</a></td>";
		} else {
			str += "<td>还没有备份过，不能进行恢复哦</td>";
		}

		str += "</tr>";
	}
	if (list.length == 0) {
		str = "<tr><td colspan='4' style='text-align: center;'>暂无数据</td></tr>";
	}
	$('#dsBody').html(str);
	$("#dsBody").find("tr:odd").find("td").css("background", "#fafafa");
	// $('#content').html(str);
};

var service = new EbeimService();
service.getDataSourcesByPage($offset, $pagesize, "", "", "", dsCB);